/*
 * Created by JFormDesigner on Thu May 19 20:21:58 CST 2022
 */

package jw3.c7.view;

import jw3.c7.controller.Usercontroller;

import javax.swing.*;
import java.awt.*;
import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;

/**
 * @author Brainrain
 */
public class Login extends JFrame {
    public Login() {
        initComponents();

    }
    private void button1MouseClicked(MouseEvent e) {
        // TODO add your code here
        String user=textField1.getText();
        String pwd=new String(passwordField1.getPassword());
        if (!user.equals("")&& !pwd.equals("")){
            if (Usercontroller.login(user,pwd)){
                JOptionPane.showMessageDialog(null,"登录成功");
                Home home=new Home();
            }else {
                JOptionPane.showMessageDialog(null,"登录失败");
            }
        }else {
            JOptionPane.showMessageDialog(null,"账号或密码不能为空");
        }
    }

    private void button2MouseClicked(MouseEvent e) {
        // TODO add your code here
        Register rg=new Register();
        rg.setVisible(true);
    }

    private void button3MouseClicked(MouseEvent e) {
        // TODO add your code here
        Cpassword cpassword=new Cpassword();
    }
    private void initComponents() {
        // JFormDesigner - Component initialization - DO NOT MODIFY  //GEN-BEGIN:initComponents
        textField1 = new JTextField();
        passwordField1 = new JPasswordField();
        label6 = new JLabel();
        label7 = new JLabel();
        button1 = new JButton();
        button2 = new JButton();
        button3 = new JButton();

        //======== this ========
        setTitle("\u4e0d\u52a8\u4ea7\u7ba1\u7406\u7cfb\u7edf");
        Container contentPane = getContentPane();
        contentPane.setLayout(null);
        contentPane.add(textField1);
        textField1.setBounds(340, 170, 110, textField1.getPreferredSize().height);
        contentPane.add(passwordField1);
        passwordField1.setBounds(340, 215, 109, passwordField1.getPreferredSize().height);

        //---- label6 ----
        label6.setText("\u8d26\u53f7");
        label6.setForeground(Color.white);
        contentPane.add(label6);
        label6.setBounds(285, 175, 44, label6.getPreferredSize().height);

        //---- label7 ----
        label7.setText("\u5bc6\u7801");
        label7.setForeground(Color.white);
        contentPane.add(label7);
        label7.setBounds(285, 220, 44, 17);

        //---- button1 ----
        button1.setText("\u767b\u5f55");
        button1.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                button1MouseClicked(e);
            }
        });
        contentPane.add(button1);
        button1.setBounds(new Rectangle(new Point(310, 275), button1.getPreferredSize()));

        //---- button2 ----
        button2.setText("\u6ce8\u518c");
        button2.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                button2MouseClicked(e);
            }
        });
        contentPane.add(button2);
        button2.setBounds(new Rectangle(new Point(415, 275), button2.getPreferredSize()));

        //---- button3 ----
        button3.setText("\u5fd8\u8bb0\u5bc6\u7801?");
        button3.addMouseListener(new MouseAdapter() {
            @Override
            public void mouseClicked(MouseEvent e) {
                button3MouseClicked(e);
            }
        });
        contentPane.add(button3);
        button3.setBounds(new Rectangle(new Point(355, 310), button3.getPreferredSize()));

        {
            // compute preferred size
            Dimension preferredSize = new Dimension();
            for(int i = 0; i < contentPane.getComponentCount(); i++) {
                Rectangle bounds = contentPane.getComponent(i).getBounds();
                preferredSize.width = Math.max(bounds.x + bounds.width, preferredSize.width);
                preferredSize.height = Math.max(bounds.y + bounds.height, preferredSize.height);
            }
            Insets insets = contentPane.getInsets();
            preferredSize.width += insets.right;
            preferredSize.height += insets.bottom;
            contentPane.setMinimumSize(preferredSize);
            contentPane.setPreferredSize(preferredSize);
        }
        pack();
        setLocationRelativeTo(getOwner());
        // JFormDesigner - End of component initialization  //GEN-END:initComponents

        Image image1=new ImageIcon("images/黑马.png").getImage();



    }

    // JFormDesigner - Variables declaration - DO NOT MODIFY  //GEN-BEGIN:variables
    private JTextField textField1;
    private JPasswordField passwordField1;
    private JLabel label6;
    private JLabel label7;
    private JButton button1;
    private JButton button2;
    private JButton button3;
    // JFormDesigner - End of variables declaration  //GEN-END:variables
}
